package com.ahem.demo.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * RestTemplate 配置类
 * 
 * @author fangzhixian
 *
 */
@Configuration
public class RestTemplateConfiguration {
	@Bean
	public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
		RestTemplate restTemplate = new RestTemplate();
		// restTemplate.getMessageConverters().add(new
		// WxMappingJackson2HttpMessageConverter());
		restTemplate.setRequestFactory(factory);
		return restTemplate;
	}

	@Bean
	public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
		SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
		factory.setReadTimeout(5000);// 读超时ms
		factory.setConnectTimeout(15000);// 链接超时 ms
		return factory;
	}
}
